package cn.stylefeng.guns.core.common.util;

import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;

import java.util.List;
import java.util.Map;

public class MoneyDifference {


    /**
     * 如果拥有的金额减去押金大于0 则可以租车
     * @param have
     * @param moneyOneDay
     * @param day
     * @return
     */
    public static Double getMoneyDifference(Double have, Integer moneyOneDay, Long day){
        Double money = have - (moneyOneDay*day);
        if (money < 0)new ServiceException(BizExceptionEnum.MONEY_NOT_ENOUGH);
        money = moneyOneDay.doubleValue()*day;
        return money;
    }


    public static Double getRentMoney(Double moneyOneDay,Long days ){
        return moneyOneDay * days;
    }


    public static Double getDifference(Double old , Double now){
        return old - now;
    }



    public static Float getFloatDifference(float f1 , float f2){
        if (f1 == f2){
            return f1;
        }
        if ((f1 - f2) > 0 && (f1 - f2) <= 2.5){
            return f1-0.5F;
        }
        if ((f1 - f2) > 2.5 && (f1 - f2) <= 5){
            return f1-1F;
        }
        if ((f2 - f1) > 0 && (f2 - f1) <= 2.5){
            return f2-0.5F;
        }
        if ((f2 - f1) > 2.5 && (f2 - f1) <= 5){
            return f2-1F;
        }
        return 0F;
    }

    public static Double getRentMoneyHasActivity(double doubleValue, Long difference, List<Map<String, Object>> activitys) {
        Double discount = null;
        for (Map<String, Object> activity : activitys) {
            discount = ((doubleValue * difference)) * Double.valueOf(activity.get("activityDiscount").toString());
        }
        return discount;
    }
}
